//------------Sonic CD Boss Spikes Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 56: TYPE_BOSSSPIKES


sub ObjectMain
	switch Object.State
	case 0
		if Player.XPos>Object.XPos
			SetMusicTrack("JP/Menu.ogg",4,1)
			Object.State++
		endif
		if Player.XPos>Object.XPos
			Object[+3].Value2=Stage.XBoundary2
			Stage.NewXBoundary1=Object.iXPos
			Stage.NewXBoundary1+=328
			Stage.NewXBoundary1-=Screen.CenterX
			Stage.NewXBoundary2=Stage.NewXBoundary1
			Stage.NewXBoundary2+=Screen.CenterX
			Object[+3].Value1=Stage.NewXBoundary2
			Object[+3].Value1+=160
			Object[+3].Value1<<=16
			Stage.NewXBoundary2+=Screen.CenterX
			Stage.NewYBoundary2=Object.iYPos
			Object.State=1
			Object.Priority=1
			ResetObjectEntity(19,TypeName[BlankObject],0,0,0)
			SetActivePalette(0,0,Screen.YSize)
		endif
		break
	case 1
		TempValue0=Object.XPos
		TempValue0+=3145728
		if Player.XPos>TempValue0
			Object.State=2
		endif
		break
	case 2
		if Object.Value0<64
			Object.Value0+=2
			Object.YPos-=131072
		else
			Object.Value0=0
			Object.State=3
		endif
		break
	case 3
		if Object.Value0<192
			Object.Value0+=2
			Object.XPos+=131072
		else
			Object.Value0=0
			Object.State=4
			Object.Priority=0
		endif
		break

	endswitch
endsub


sub ObjectPlayerInteraction
	if Object.State<3
		PlayerObjectCollision(C_BOX,-24,-32,0,32)
	else
		PlayerObjectCollision(C_TOUCH,-64,-32,0,32)
		if CheckResult==1
			Player.XPos=Player.CollisionRight
			Player.XPos<<=16
			Player.XPos+=Object.XPos
		endif
	endif
	PlayerObjectCollision(C_TOUCH,0,-32,24,32)
	if CheckResult==1
		CallFunction(PlayerObject_Hit)
		if Player.State==PlayerObject_Hurt
			Object[+6].Value3=49152
		endif
	endif
endsub


sub ObjectDraw
	DrawSprite(0)
endsub


sub ObjectStartup
	LoadSpriteSheet("R5/Objects2.gif")
	if Object[24].PropertyValue<3
		SpriteFrame(-24,-32,48,64,125,191)
	else
		SpriteFrame(-24,-32,48,64,76,191)
	endif
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
